import adminsApi from "../../api/admins.js";
import Base from '../base.js';
export default class extends Base {
  render() {
      this.$el.html(`
    <section class="main" id="regEle">
      <div class="logo text-center">
          <h1> <a href="index.html"> 后台人员注册</a></h1> 
      </div>
      <div class="content-w3ls text-center">
      <a href="#/usersReg"><div class="img-responsive"></div></a>
          <form action="#" method="post">
              <div class="wthree-field">
                  <input name="username" id="username" type="text" value="z4" placeholder="账号" required>
              </div>
              <div class="wthree-field">
                  <input name="password" id="myInput" type="Password" value="123" placeholder="密码">
              </div>
              <div class="wthree-field">
                  <button type="button" class="btn" name="reg-btn">确认注册</button>
              </div>
              <div class="login-bottom">
                  <a href="https://www.csdn.net" class="">help</a>
              </div>
          </form>
      </div>
      <div class="copyright">
          <p>©2021 Four groups<a href="https://baidu.com" target="_blank">The tail</a></p>
      </div>
</section>
  `);
      this.$usernameEle = $("input[name=username]"); //获取输入用户名
      this.$passwordEle = $("input[name=password]");//获取输入密码
      this.$regBtn = $("button[name=reg-btn]"); //获取注册按钮
  }
  async regHandle() {
    
      const adminsname = this.$usernameEle.val(); //获取输入的值
      const adminspassword = this.$passwordEle.val();

      const data=await adminsApi.adminsReg({
        adminsname,
        adminspassword,
      });
      if (data) {
        // adminsApi.setToken(token);
        layer.msg("注册成功");
        location.hash = "#/login";
        return;
      }
          // 登录失败弹窗
    layer.msg("注册失败，账号已存在，5秒自动关闭", {
        time: 5*1000
        ,success: function(layero, index){
          var timeNum = this.time/1000, setText = function(start){
            layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
          };
          setText(!0);
          this.timer = setInterval(setText, 1000);
          if(timeNum <= 0) clearInterval(this.timer);
        }
        ,end: function(){
          clearInterval(this.timer);
        },
        btn: ['确定','取消','返回']
      });  
  }
  handle() {
      this.$regBtn.on("click", this.regHandle.bind(this));
  }
};
// console.log(Base.data);
// module.exports={data}